﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class SysYcjy_pwd : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Session["sTittle"] = "我的帐户>>修改密码";
    }
    protected void ChangePasswordPushButton_Click(object sender, EventArgs e)
    {
        string userName= Session["sUserName"].ToString();
        string pwd = CurrentPassword.Text.Trim();
        string newPwd=NewPassword.Text.Trim();
        if (Membership.ValidateUser(userName, pwd))
        {
            MembershipUser user = Membership.GetUser(userName);
            if(newPwd.Length < 6)
            {
                Response.Write(string.Format("<script language='javascript'>alert('{0}');window.location.href='pwdChange.aspx'</script>", "修改失败,密码不能少于6位"));
                Response.End();
            }
            if (user.ChangePassword(pwd, newPwd))
            {
                Response.Write(string.Format("<script language='javascript'>alert('{0}')</script>", "修改成功"));
            }
            else
            {
                Response.Write(string.Format("<script language='javascript'>alert('{0}')</script>", "修改失败"));
            }
        }
        else
        {
            Response.Write(string.Format("<script language='javascript'>alert('{0}')</script>", "旧密码错误"));
        }
    }
}
